#include "Scheme/GUIImage.h"
#include "Scheme/GUIImageset.h"
#include "GUIBase.h"
#include "GUILogger.h"

namespace YGUI
{
    Image::Image(const Imageset* owner, const String& name, const Rect<float>& area, const Point<float>& offset,
        float horzScale/* = 1.0f*/, float vertScale/* = 1.0f*/) : 
        m_owner(owner), 
        m_name(name), 
        m_area(area), 
        m_offset(offset)
    {
        setHorzScale(horzScale);
        setVertScale(vertScale);
    }

    Image::Image(const Image& img) : 
        m_owner(img.m_owner), 
        m_name(img.m_name), 
        m_area(img.m_area),
        m_offset(img.m_offset),
        m_scaleOffset(img.m_scaleOffset), 
        m_scaleSize(img.m_scaleSize)
    {
    }

    const String& Image::getSetName(void) const
    {
        return m_owner->getName();
    }

    void Image::setHorzScale(float scale)
    {
        m_scaleSize.m_width = YGUI::PixelAligned<float>(m_area.getWidth() * scale);
        m_scaleOffset.m_x = YGUI::PixelAligned<float>(m_offset.m_x * scale);
    }

    void Image::setVertScale(float scale)
    {
        m_scaleSize.m_height = YGUI::PixelAligned<float>(m_area.getHeight() * scale);
        m_scaleOffset.m_y = YGUI::PixelAligned<float>(m_offset.m_y * scale);
    }

    void Image::draw(GeometryBuffer& buff, const Rect<float>& dest_rect, const Rect<float>* clip_rect, const ColourRect& colour, QuadSplitMode split_mode/* = YGUI::LeftTopToRightBottom*/) const
    {
        Rect<float> dest(dest_rect);
        dest.offset(m_scaleOffset);
        m_owner->draw(buff, m_area, dest, clip_rect, colour, split_mode);
    }
};
